<template>
  <el-tree :props="props" :load="loadNode" lazy @node-click="nodeClick">
  </el-tree>
</template>

<script>
export default {
  name: "PromptTree",
  data() {
    return {
      props: {
        label: "name",
        children: "zones",
        isLeaf: "leaf",
      },
    };
  },
  methods: {
    /**
     * 点击node节点
     */
    nodeClick(data) {
    //   console.log("----data-------", data);
      this.$emit("changeTree", data);
    },
    loadNode(node, resolve) {
      if (node.level === 0) {
        this.$api.typeSelect().then((res) => {
          // console.log("===== tree", res);
          if (res.status === 200) {
            return resolve(res.result);
          }
        });
      }
      if (node.level >= 1) {
        this.$api
          .typeSelect({
            id: node.data.cid,
          })
          .then((res) => {
            // console.log("===== tree", res);
            if (res.status === 200) {
              return resolve(res.result);
            } else {
              return resolve([]);
              
            }
          });
      }
    },
  },
};
</script>

<style lang="less" scoped>
</style>